package com.zidongxiangxi.sharding.job.core.listener;

import org.apache.curator.framework.recipes.cache.TreeCacheEvent;

/**
 * 节点变更监听基类
 *
 * @author chenxudong
 * @date 2021/02/22
 */
public abstract class AbstractNodeChangeListener implements NodeChangeListener {
    @Override
    public final void dataChanged(final String path, final TreeCacheEvent.Type eventType, final String data) {
        if (canHandleChange(path, eventType)) {
            dealDataChange(path, eventType, data);
        }
    }

    /**
     * 是否可以处理变更
     *
     * @param path 路径
     * @param eventType 事件类型
     * @return 是否可以处理变更
     */
    abstract boolean canHandleChange(final String path, final TreeCacheEvent.Type eventType);

    /**
     * 处理数据变更
     *
     * @param path 路径
     * @param eventType 事件类型
     * @param data 数据
     */
    abstract void dealDataChange(final String path, final TreeCacheEvent.Type eventType, final String data);
}
